﻿#define _CRT_SECURE_NO_WARNINGS 1
#include <iostream>
#include <vector>
using namespace std;

//寻找旋转排序数组中的最小值
//解法一：
class Solution {
public:
    int findMin(vector<int>& nums) {
        int left = 0, right = nums.size() - 1;
        int n = nums.size();
        while (left < right)
        {
            int mid = left + (right - left) / 2;
            if (nums[mid] > nums[0]) left = mid + 1;
            else right = mid;
        }
        //处理边界条件
        if (n == 1) return nums[0];
        if (nums[0] > nums[1]) return nums[1];
        if (nums[0] < nums[n - 1]) return nums[0];
        return nums[left];
    }
};

//解法二：
class Solution1
{
public:
    int findMin(vector<int>& nums)
    {
        int left = 0, right = nums.size() - 1;
        int x = nums[right]; // 标记⼀下最后⼀个位置的值
        while (left < right)
        {
            int mid = left + (right - left) / 2;
            if (nums[mid] > x) left = mid + 1;
            else right = mid;
        }
        return nums[left];
    }
};


class Solution2 {
public:
    int missingNumber(vector<int>& nums) {
        int left = 0, right = nums.size() - 1;
        while (left < right)
        {
            int mid = left + (right - left) / 2;
            if (nums[mid] == mid) left = mid + 1;
            else right = mid;
        }
        return left == nums[left] ? left + 1 : left;
    }
};

int main()
{
	return 0;
}